package com.googlecode.lemyriapode.type;

import com.googlecode.lemyriapode.regle.Position;
import com.googlecode.lemyriapode.regle.Position.Piece;
import com.googlecode.lemyriapode.type.ChessCategory.IPredicate;
import com.googlecode.lemyriapode.type.Echiquier.Case;
import com.googlecode.lemyriapode.type.Echiquier.Direction;


public abstract  class PredClos implements IPredicate{

    Direction direction;
    Piece piece;
    Position position;
    Case _case;

    public abstract boolean eval();
}
//class CRienAFaire extends PredClos {
//
//    @Override
//    public void exec() {
//    }
//};

class PFinDirection extends PredClos  {

    public boolean eval() {
        return !(direction.ordinal() > 7);
    }
}

class PCaseInexistente extends PredClos  {

    public boolean eval() {
        return !_case.equals(Case.out);


    }
}

class PPieceAJouer extends PredClos  {

    public boolean eval() {
        return (piece != null) && (piece.isCouleur() && position.isTrait());
    }
}

class PDirectionAutorise extends PredClos {

    public boolean eval() {
        return direction.estInclus(piece.getRegle_deplacement());
    }
}

class PDeplacementNCase extends PredClos {

    public boolean eval() {
        return piece.isNCase();
    }
}

class PredClosFactory {

    public enum PredClosType {

        FinDirection, CaseInexistente,
        DeplacementNCase, DirectionAutorise,
        PieceAJouer, RienAFaire
    }

    public static PredClos create(PredClosType predClosType) {
        switch (predClosType) {
            case FinDirection:
                return new PFinDirection();
            case CaseInexistente:
                return new PCaseInexistente();
            case DeplacementNCase:
                return new PDeplacementNCase();
            case DirectionAutorise:
                return new PDirectionAutorise();
            case PieceAJouer:
                return new PPieceAJouer();
//            case RienAFaire:
//                return new CRienAFaire();
        }
        throw new IllegalArgumentException(predClosType + " is not recognized.");
    }
}



